/*HNMCc1joYd2y+PzAFeGZrpIjq0jiBUM1NqvptvWirn4JeIL759ieqTBxComIraBk*/
/*
 * @Author: guoylei
 * @PageInfo: 暂存
 * @Date: 2021-07-05 22:39:34
 * @Last Modified by: zhangflr
 * @Last Modified time: 2021-11-04 16:21:59
 */
import { ACTIONS } from 'scmpub/scmpub/components/TempSave';
import { setDefData } from '../../../../../scmpub/scmpub/pub/cache';
import { PAGECODE, AREA, DATASOURCECACHE, TEMPSAVECONFIG } from '../../constance';
import { showErrorInfo } from '../../../../../scmpub/scmpub/pub/tool/messageUtil';
import { getLangByResId } from '../../../../../scmpub/scmpub/pub/tool/multiLangUtil';
export default function temporaryStorage(props) {
	//拼装参数：页面模板编码，表头ID，表体ID，参数类型
	let config = {
		pagecode: PAGECODE.cardPagecode,
		formId: AREA.cardFormId,
		tableId: [
			AREA.cardTableId,
			AREA.cardTermId,
			AREA.cardPayId,
			AREA.cardFeeId,
			AREA.cardMemoraId,
			AREA.cardChangeId,
			AREA.cardExecutId
		],
		type: TEMPSAVECONFIG.type,
		area: AREA.cardTableId,
		param: 'pk_material'
	};
	//设置缓存
	setDefData(DATASOURCECACHE.tempCardCacheKey, TEMPSAVECONFIG.tempsave, true);
	//调用暂存保存草稿方法，发送请求
	ACTIONS.SAVE.call(this, props, config, checkTempSave.bind(this));
}

//暂存保存草稿方法回调，可通过条件判断是否执行保存草稿
function checkTempSave() {
	let option = this.props.getUrlParam('option');
	let status = this.props.getUrlParam('status');
	if (status == 'modify' || (status == 'edit' && option != 'copy')) {
		showErrorInfo('', getLangByResId(this, '4004PURDAILY-000070')); /* 国际化处理： 已保存单据不支持暂存！*/
		setDefData(DATASOURCECACHE.tempCardCacheKey, 'tempsave', false);
		return false;
	}
	let srcids = this.props.cardTable.getColValue(AREA.cardTableId, 'csrcid');
	if (!srcids || srcids.length == 0) {
		return true;
	}
	let ischeck = false;
	srcids.forEach((srcid) => {
		if (srcid.value) {
			ischeck = true;
		}
	});
	if (ischeck) {
		showErrorInfo('', getLangByResId(this, '4004PURDAILY-000071')); /* 国际化处理： 单据存在来源，不能支持暂存！*/
		setDefData(DATASOURCECACHE.tempCardCacheKey, 'tempsave', false);
		return false;
	}
	return true;
}

/*HNMCc1joYd2y+PzAFeGZrpIjq0jiBUM1NqvptvWirn4JeIL759ieqTBxComIraBk*/